package chixing.day19.work;

import java.util.ArrayList;
import java.util.List;

public class Order {
    private User user;
    private List<Product> product;
    private double originalTotalPrice;

    public Order(User user, List<Product> product, double originalTotalPrice) {
        this.user = user;
        this.product = new ArrayList<>();
        this.product.addAll(product);
        calculateTotalPrice();
    }

    public Order() {
        this.product = new ArrayList<>();
    }
    private void calculateTotalPrice() {
        this.originalTotalPrice = 0;
        for(Product p : product) {
            this.originalTotalPrice += p.getPrice();
        }
    }


    @Override
    public String toString() {
        return "Order{" +
                "user=" + user +
                ", product=" + product +
                ", originalTotalPrice=" + originalTotalPrice +
                '}';
    }

    public User getUser() {
        return user;
    }

    public void setUser(User user) {
        this.user = user;
    }

    public List<Product> getProduct() {
        return product;
    }

    public void setProduct(List<Product> product) {
        this.product = product;
        calculateTotalPrice();
    }

    public double getOriginalTotalPrice() {
        return originalTotalPrice;
    }

    public void setOriginalTotalPrice(double originalTotalPrice) {
        this.originalTotalPrice = originalTotalPrice;
    }
}
